//
//  tabbarView.m
//  tabbarTest
//
//  Created by Kevin Lee on 13-5-6.
//  Copyright (c) 2013年 Kevin. All rights reserved.
//

#import "tabbarView.h"

#import "JTCSM.h"
//#import "XGT.h"
#define KBtnHeight 49
#define RGBACOLOR(r,g,b,a) [UIColor colorWithRed:(r)/255.0 green:(g)/255.0 blue:(b)/255.0 alpha:(a)]

@implementation tabbarView

- (id)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        width = frame.size.width;
        height = frame.size.height;
        [self setFrame:frame];
        [self setBackgroundColor:[UIColor clearColor]];
        [self layoutView];
    }
    return self;

}

-(void)layoutView
{
    _tabbarView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@""]];
    _tabbarView.frame = CGRectMake(0, 0, width, KBtnHeight);
    [_tabbarView setUserInteractionEnabled:YES];
    [self addSubview:_tabbarView];
    [self layoutBtn];

}

-(void)layoutBtn
{
    CGFloat num = 3;
    _button_1 = [CustomButton buttonWithType:UIButtonTypeCustom];
    [_button_1 systemButtonWithFrame:CGRectMake(0, 0, width/num, KBtnHeight) imageName:@"icon_01press@2x.png" title:@"首页" target:self action:@selector(btn1Click:)];
    [_button_1 setTag:101];
    [_tabbarView addSubview:_button_1];
    _button_1.label.textColor = [df colorWithHexString:@"c2c2c2" alpha:1];
    _button_2 = [CustomButton buttonWithType:UIButtonTypeCustom];
    [_button_2 systemButtonWithFrame:CGRectMake(width/num, 0, width/num, KBtnHeight) imageName:@"icon_02normal@2x.png" title:@"明细" target:self action:@selector(btn1Click:)];
    [_button_2 setTag:102];
    [_tabbarView addSubview:_button_2];
    
    _button_3 = [CustomButton buttonWithType:UIButtonTypeCustom];
    [_button_3 systemButtonWithFrame:CGRectMake(width*2/num, 0, width/num, KBtnHeight) imageName:@"icon_03normal@2x.png" title:@"我的" target:self action:@selector(btn1Click:)];
    [_button_3 setTag:103];
    [_tabbarView addSubview:_button_3];
    
//    _button_4 = [CustomButton buttonWithType:UIButtonTypeCustom];
//    [_button_4 systemButtonWithFrame:CGRectMake(width*3/num, 0, width/num, KBtnHeight) imageName:@"icon_04normal@2x.png" title:@"我的" target:self action:@selector(btn1Click:)];
//    [_button_4 setTag:104];
//    [_tabbarView addSubview:_button_4];


}

-(void)btn1Click:(id)sender
{
    
    UIColor *disSelectColor = [df colorWithHexString:@"c2c2c2" alpha:1];
    UIColor *color = [df colorWithHexString:@"222222" alpha:1];

    UIButton *btn = (UIButton *)sender;
    _button_1.label.textColor = disSelectColor;
    _button_2.label.textColor = disSelectColor;
    _button_3.label.textColor = disSelectColor;
    _button_4.label.textColor = disSelectColor;
    
    
    _button_1.imgView.image =  [UIImage imageNamed:@"icon_01normal@2x.png"];
    _button_2.imgView.image =  [UIImage imageNamed:@"icon_02normal@2x.png"];
    _button_3.imgView.image =  [UIImage imageNamed:@"icon_03normal@2x.png"];
    _button_4.imgView.image =  [UIImage imageNamed:@"icon_04normal@2x.png"];
    switch (btn.tag) {
        case 101:
        {
            
            
            _button_1.label.textColor = color;
            
            _button_1.imgView.image =   [UIImage imageNamed:@"icon_01press@2x.png"];
            
            [self.delegate touchBtnAtIndex:0];
            
            break;
        }
        case 102:
        {
            _button_2.label.textColor = color;
            
            _button_2.imgView.image =  [UIImage imageNamed:@"icon_02press@2x.png"];


            [self.delegate touchBtnAtIndex:1];
            break;
        }
        case 103:
        {

            _button_3.label.textColor = color;
           

            _button_3.imgView.image =  [UIImage imageNamed:@"icon_03press@2x.png"];

            [self.delegate touchBtnAtIndex:2];
            break;
        }
        case 104:
        {

            _button_4.label.textColor =color;
            _button_4.imgView.image =  [UIImage imageNamed:@"icon_04press@2x.png"];

            [self.delegate touchBtnAtIndex:3];
            
            break;
        }

            default:
        break;
    }
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
    // Drawing code
}
*/

@end
